package com.ruoyi.quartz.domain;


import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 
* @ClassName: ResponseCode
* @Description: 返回状态码常量类
* @author pengjun
* @date 2019年1月10日
*
 */
public class ResponseCode implements Serializable {
	
    private static final long serialVersionUID = -2790656454339569762L;
    
	public static final String OK = "OK";

    public static final String SUCCESS_CODE = "200";
    public static final String SUCCESS_MESG = "请求处理成功";

    public static final String SYSTEM_FAIL_CODE = "500";
    public static final String SYSTEM_FAIL_MESG = "系统异常, 请联系系统管理员";

    //系统
    public static final String PARAM_ERROR_CODE = "400";



    //参数相关code码000001开始
    public static final String ARGUMENT_INVALID_CODE = "000001";
    public static final String ARGUMENT_INVALID_MESG = "数据为空，请检查必填参数！";

    public static final String ARGUMENT_TYPE_CODE = "000002";
    public static final String ARGUMENT_TYPE_MESG = "参数数据类型错误！";

    public static final String ARGUMENT_LENGTH_CODE = "000003";
    public static final String ARGUMENT_LENGTH_MESG = "参数长度超过规定长度！";

    public static final String ARGUMENT_FORMAT_CODE = "000004";
    public static final String ARGUMENT_FORMAT_MESG = "参数格式错误,请输入正常数据格式！";

    public static final String ARGUMENT_PASD_FAIL_CODE = "000005";
    public static final String ARGUMENT_PASD_FAIL_MESG = "您输入的原密码不正确，请重新输入！";

    public static final String ARGUMENT_PASD_NULL_CODE = "000006";
    public static final String ARGUMENT_PASD_NULL_MESG = "新密码不能为空，请重新输入！";

    public static final String ARGUMENT_VERIFY_NULL_CODE = "000007";
    public static final String ARGUMENT_VERIFY_NULL_MESG = "校验码已失效，请重新获取！";

    public static final String ARGUMENT_DELETE_ERROR_CODE = "000008";
    public static final String ARGUMENT_DELETE_ERROR_MESG = "没有此条数据，删除失败！";

    public static final String ARGUMENT_PHONE_REPEAT_CODE = "000009";
    public static final String ARGUMENT_PHONE_REPEAT_MESG = "此号码已被使用，请输入其他电话号码！";

    public static final String ARGUMENT_USER_REPEAT_CODE = "000010";
    public static final String ARGUMENT_USER_REPEAT_MESG = "此用户名已被占用，请输入其他用户名！";

    public static final String ARGUMENT_PARAM_ERROR_CODE = "000011";
    public static final String ARGUMENT_PARAM_ERROR_MESG = "请输入正确的电话号码！";

    public static final String ARGUMENT_NONEXISTENT_PARAM_CODE = "000012";
    public static final String ARGUMENT_NONEXISTENT_PARAM_MESG = "请输入正确的电话号码！";

    public static final String ARGUMENT_EXIST_NAME_CODE = "000013";
    public static final String ARGUMENT_EXIST_NAME_MESG = "此资源名称已经存在！";

    public static final String ARGUMENT_VERIFY_ERROR_CODE = "000014";
    public static final String ARGUMENT_VERIFY_ERROR_MESG = "校验码输入错误，请重新输入！";

    public static final String ARGUMENT_PHONE_ERROR_CODE = "000015";
    public static final String ARGUMENT_PHONE_ERROR_MESG = "请输入正确的电话号码！";

    // 文件操作code起始码 200001
    public static final String ARGUMENT_INVALID_EMAIL_GET_SEND_LOG = "200001";
    public static final String ARGUMENT_INVALID_EMAIL_GET_SEND_MESG = "获取数据异常";

    public static final String ARGUMENT_INVALID_EMAIL_UPLOAD_FILE_LOG = "200002";
    public static final String ARGUMENT_INVALID_EMAIL_UPLOAD_FILE_MESG = "上传文件错误";

    public static final String ARGUMENT_INVALID_EMAIL_DOWNLOAD_FILE_LOG = "200003";
    public static final String ARGUMENT_INVALID_EMAIL_DOWNLOAD_FILE_MESG = "文件没有找到或者文件读取、关闭异常";

    public static final String ARGUMENT_INVALID_EMAIL_AUDIT_STATUS_CODE = "200004";
    public static final String ARGUMENT_INVALID_EMAIL_AUDIT_STATUS_MESG = "邮件已经审核,请勿重复审核";

    // Token异常起始码 300001
    public static final String ARGUMENT_INVALID_ADD_TOKEN_LOG = "300001";
    public static final String ARGUMENT_INVALID_ADD_TOKEN_MESG = "Token入库异常";
    public static final String INVALID_CODE_ERROR = "300002";
    public static final String INVALID_CODE_ERROR_MESG = "验证码错误";
    public static final String INVALID_CODE_INVALID = "300003";
    public static final String INVALID_CODE_INVALID_MESG = "验证码失效";

    public static final String INVALID_CODE_TOKEN_FAILURE = "300004";
    public static final String INVALID_CODE_TOKEN_FAILURE_MESG = "token失效";
    public static final String INVALID_CODE_SESSION_FAILURE = "300005";
    public static final String INVALID_CODE_SESSION_FAILURE_MESG = "session失效";

    //逻辑判断
    public static final String USER_ALREADY_EXISTS_CODE="400001";
    public static final String USER_ALREADY_EXISTS_MESG="该用户已存在预警配置";

    public static final String USER_SELECT_CODE="400002";
    public static final String USER_SELECT_MESG="查询返回结果为空";

    //发送短信返回提示语
    public static final String MESSAGE_SENDING_INFORMATION_SUCCESS_MESG="发送成功";
    public static final String MESSAGE_SENDING_INFORMATION_FAIL_ONE_MESG="超过一分钟内一条消息的限制";
    public static final String MESSAGE_SENDING_INFORMATION_FAIL_FIVE_MESG="超过一小时五条消息的限制";
    public static final String MESSAGE_SENDING_INFORMATION_FAIL_TEN_MESG="超过一天十条消息的限制";
    public static final String MESSAGE_SENDING_INFORMATION_FAIL_MESG="短信发送异常";
    /**
     * 响应码MAP
     */
    private static Map<String, String> RESPONSE_CODE_MAPPING;

    static {
        RESPONSE_CODE_MAPPING = new HashMap<String, String>();
        // 统一成功码
        RESPONSE_CODE_MAPPING.put(SUCCESS_CODE, SUCCESS_MESG);
        // 统一异常码
        RESPONSE_CODE_MAPPING.put(SYSTEM_FAIL_CODE, SYSTEM_FAIL_MESG);

        // 数据为空，请检查必填参数
        RESPONSE_CODE_MAPPING.put(ARGUMENT_INVALID_CODE, ARGUMENT_INVALID_MESG);
        //参数数据类型错误
        RESPONSE_CODE_MAPPING.put(ARGUMENT_TYPE_CODE, ARGUMENT_TYPE_MESG);
        //参数长度超过规定长度
        RESPONSE_CODE_MAPPING.put(ARGUMENT_LENGTH_CODE, ARGUMENT_LENGTH_MESG);
        //参数格式错误,请输入正常数据格式
        RESPONSE_CODE_MAPPING.put(ARGUMENT_FORMAT_CODE, ARGUMENT_FORMAT_MESG);
        //您输入的原密码不正确，请重新输入
        RESPONSE_CODE_MAPPING.put(ARGUMENT_PASD_FAIL_CODE, ARGUMENT_PASD_FAIL_MESG);

        // 邮件审核错误返回码
        RESPONSE_CODE_MAPPING.put(ARGUMENT_INVALID_EMAIL_AUDIT_STATUS_CODE, ARGUMENT_INVALID_EMAIL_AUDIT_STATUS_MESG);

        // 获取数据异常
        RESPONSE_CODE_MAPPING.put(ARGUMENT_INVALID_EMAIL_GET_SEND_LOG, ARGUMENT_INVALID_EMAIL_GET_SEND_MESG);
        // 上传文件错误
        RESPONSE_CODE_MAPPING.put(ARGUMENT_INVALID_EMAIL_UPLOAD_FILE_LOG, ARGUMENT_INVALID_EMAIL_UPLOAD_FILE_MESG);
        // 文件没有找到或者文件读取、关闭异常
        RESPONSE_CODE_MAPPING.put(ARGUMENT_INVALID_EMAIL_DOWNLOAD_FILE_LOG, ARGUMENT_INVALID_EMAIL_DOWNLOAD_FILE_MESG);
        // Token入库异常
        RESPONSE_CODE_MAPPING.put(ARGUMENT_INVALID_ADD_TOKEN_LOG, ARGUMENT_INVALID_ADD_TOKEN_MESG);
        //token失效
        RESPONSE_CODE_MAPPING.put(INVALID_CODE_TOKEN_FAILURE, INVALID_CODE_TOKEN_FAILURE_MESG);
        //session失效
        RESPONSE_CODE_MAPPING.put(INVALID_CODE_SESSION_FAILURE, INVALID_CODE_SESSION_FAILURE_MESG);
        RESPONSE_CODE_MAPPING.put(USER_ALREADY_EXISTS_CODE,USER_ALREADY_EXISTS_MESG);
        
    }
  

    /**
     * 响应码
     */
    private String code;

    /**
     * 响应内容
     */
    private String mesg;

    /**
     * 消息代码是否无效
     */
    private boolean isInvalidCode = false;

    public ResponseCode(final String code) {
        this.code = code;
        mesg = null;
    }

    public ResponseCode(final String code, final String mesg) {
        this.code = code;
        this.mesg = mesg;
    }

    public static String getMessage(final String code) {
        return ResponseCode.getMessage(code, false);
    }

    public static String getMessage(final String code, final boolean showCode) {
        String mesg = RESPONSE_CODE_MAPPING.get(code);
        ResponseCode responseCode = new ResponseCode(code, mesg);

        if (StringUtils.isEmpty(mesg)) {
            responseCode.isInvalidCode = true;
        }

        return responseCode.toString(showCode);
    }

    @Override
    public String toString() {
        return this.toString(true);
    }

    public String toString(final boolean showCode) {
        String returnString = "";

        if (showCode) {
            returnString = "[" + code + "] " + mesg;
        } else {
            returnString = mesg;
        }

        return returnString;
    }

    public boolean isInvalidErrorNumber() {
        return isInvalidCode;
    }
}
